2012-07-22 46 views
1

我正在爲Android構建phonegap應用程序,並且需要使用javascript從包含在應用程序的www目錄中的.jpg中設置壁紙的方法。我將如何構建一個與我的phonegap應用程序www文件夾中的資源配合使用的phonegap插件?從www資產手機設置壁紙? Android

+0

您將不得不將任何資源文件夾中要使用的資源複製到SDCard,因爲應用程序未運行時應用程序中的資產不可訪問。 – dda 2012-07-22 13:49:34

回答

0

只是從資產文件夾中讀取文件。與插件

​​

這是JavaScript文件test.js

var TestPlugin = function() {}; 

TestPlugin.prototype.set = function (ms, successCallback, failureCallback) { 
// navigator.notification.alert("OMG"); 
    return cordova.exec(successCallback, failureCallback, 'testPlugin', "setWallPaper", [ms]); 
}; 

PhoneGap.addConstructor(function() { 
    PhoneGap.addPlugin("test", new TestPlugin()); 
}) 

和主文件調用插件與映像文件名稱

window.plugins.test.set("imageFileName.jpg", 
     function() { 
      navigator.notification.alert("Set Success");  
     }, 
     function (e) { 
      navigator.notification.alert("Set Fail: " + e); 
     } 
    ); 

; 

與Android設備的相關權限

<uses-permission android:name="android.permission.SET_WALLPAPER" /> 

和插件.xml

<plugin name="testPlugin" value="com.android.test.testPlugin"/>