小编use*_*538的帖子

从android启动服务时的权限问题

我已将服务编写为应用程序的一部分.我尝试使用以下代码从第二个应用程序调用此服务:

    Intent intent = new Intent () ;
    intent.setClassName("com.test" ,"com.test.DownloadService") ;
    // Create a new Messenger for the communication back
    Messenger messenger = new Messenger(handler);
    intent.putExtra("MESSENGER", messenger);
    intent.setData(Uri.parse("http://www.vogella.com/index.html"));
    intent.putExtra("urlpath", "http://www.vogella.com/index.html");
    this.startService(intent);
Run Code Online (Sandbox Code Playgroud)

它给出了以下例外

07-10 09:27:28.819: ERROR/AndroidRuntime(4226): FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.inject/com.inject.MyActivity}: java.lang.SecurityException: Not allowed to start service Intent { dat=http://www.vogella.com/index.html cmp=com.test/.DownloadService (has extras) } without permission not exported from uid 10109
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1971)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1996)
    at android.app.ActivityThread.access$700(ActivityThread.java:126)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1156)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4458)
    at java.lang.reflect.Method.invokeNative(Native …
Run Code Online (Sandbox Code Playgroud)

android android-intent android-service android-permissions

13
推荐指数
2
解决办法
2万
查看次数

即使值为null,Sqlite查询返回0

以下是我用来获取对应于我的sqlite db表中特定字段的int值的查询.

"SELECT conn_status FROM profiles WHERE devID = '" + id+"'"
Run Code Online (Sandbox Code Playgroud)

如果没有为与提供的devID相对应的'conn_status'保存值,则表中的现有值将为null.我从java检索数据,如下所示:

c.getInt(c.getColumnIndex("conn_status"))
Run Code Online (Sandbox Code Playgroud)

这里的问题是,使用给定的查询,即使字段中存在的值为null,c.getInt也会返回0.如何修改此查询,如果值为null,则返回不同的值而不是0,例如5.

任何帮助表示赞赏.

sqlite android

7
推荐指数
2
解决办法
9547
查看次数

将目录和文件从res/raw文件夹复制到SD卡 - android

我有一个文件夹,其中包含几个文件和一些目录,我需要在我第一次启动应用程序时复制到我的SD卡的/ mnt/sdcard/Android/data/path,当然,如果还没有所需的文件夹在那条路上不存在.

我将把这个文件夹放在我的应用程序的res/raw文件夹中.

我需要做的一步一步的程序是什么,我可以将文件夹及其所有内容从res/raw复制到SD卡中的指定路径.

任何帮助深表感谢.

编辑

以下是帮助其他人的解决方案:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    copyFileOrDir("edu1");//directory name in assets
}
File sdCard = Environment.getExternalStorageDirectory();
private void copyFileOrDir(String path) {
    AssetManager assetManager = this.getAssets();
    String assets[] = null;
    try {
        assets = assetManager.list(path);
        if (assets.length == 0) {
            copyFile(path);
        } else {
            File dir = new File (sdCard.getAbsolutePath() + "/" + "Android/data");
            //String fullPath = "/data/data/" + this.getPackageName() + "/" + path;//path for storing internally to data/data
            //File dir = new …
Run Code Online (Sandbox Code Playgroud)

java android android-widget android-intent android-sdk-2.1

6
推荐指数
1
解决办法
7617
查看次数

使用android:protectionLevel ="signature"的问题

我试图阻止应用程序绑定到服务,如果它们没有与包含应用程序相同的证书签名.为此,我通过使用元素在清单(包含服务的应用程序)中声明了一个新权限,并将新权限的protectionLevel设置为Signature,如图所示.

<permission android:name="jp.co.abc.android.OMRSSettings.permission.Access"
android:protectionLevel="signature"></permission>

<uses-permission android:name="jp.co.abc.android.OMRSSettings.permission.Access"/>
Run Code Online (Sandbox Code Playgroud)

然后,在服务的清单声明中,我使用android:permission属性,以便需要此新权限绑定到服务.

<service android:name="jp.co.xyz.bluetooth.profile.TIPServer"
 android:permission="jp.co.abc.android.OMRSSettings.permission.Access" >
<intent-filter>
<action android:name="jp.co.xyz.bluetooth.api.ICommonResultCallback" />
<action android:name="jp.co.xyz.bluetooth.api.ITimeServer" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)

我尝试从另一个应用程序访问此服务.在第二个应用程序的清单中,我添加<uses-permission android:name="jp.co.abc.android.OMRSSettings.permission.Access"/> 并尝试绑定到第一个应用程序的服务.

但我得到以下例外.

01-02 00:06:54.531: INFO/PowerManagerService(425): Start Light.setBrightness(), [20],  [3]
01-02 00:06:56.473: INFO/PowerManagerService(425): Start Light.setBrightness(), [130], [3]
01-02 00:06:58.055: WARN/dalvikvm(4956): threadid=1: thread exiting with uncaught exception (group=0x40b70390)
01-02 00:06:58.055: WARN/ActivityManager(425): Permission Denial: Accessing service ComponentInfo{jp.co.abc.android.omrsettings/jp.co.xyz.bluetooth.profile.TIPServer} from   pid=4956, uid=10158 requires jp.co.abc.android.OMRSSettings.permission.Access
01-02 00:06:58.065: ERROR/AndroidRuntime(4956): FATAL EXCEPTION: main
java.lang.SecurityException: Not allowed to bind to service Intent {     act=jp.co.xyz.bluetooth.api.ITimeServer }
at android.app.ContextImpl.bindService(ContextImpl.java:1187) …
Run Code Online (Sandbox Code Playgroud)

android android-service

5
推荐指数
2
解决办法
7253
查看次数

将目录,子目录和文件复制到SD卡 - android

我使用以下代码将特定目录及其内容复制到SD卡.该目录位于res/raw文件夹中.

以下是我使用的代码:

public class CopyActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    copyFilesToSdCard();
}

static String extStorageDirectory =  Environment.getExternalStorageDirectory().toString();
final static String TARGET_BASE_PATH = extStorageDirectory+"/Android/data/";

private void copyFilesToSdCard() {
    copyFileOrDir("");
}

private void copyFileOrDir(String path) {
    AssetManager assetManager = this.getAssets();
    String assets[] = null;
    try {
        Log.i("tag", "copyFileOrDir() "+path);
        assets = assetManager.list(path);
        if (assets.length == 0) {
            copyFile(path);
        } else {
            String fullPath =  TARGET_BASE_PATH …
Run Code Online (Sandbox Code Playgroud)

java android filenotfoundexception android-assets android-layout

4
推荐指数
1
解决办法
5661
查看次数

StaleElementReferenceException:元素不再附加到DOM:Selenium

我是自动化测试的新手.在参考了一些教程后,我创建了一个自动化测试用例.我尝试自动化的测试用例是在点击表格的一个标题后检查排序是否正常工作.

我的自动化测试用例失败,出现以下异常:

org.openqa.selenium.StaleElementReferenceException: Element is no longer attached to the DOM
Command duration or timeout: 12 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '2.25.0', revision: '17482', time: '2012-07-18 21:08:56'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.35-30-generic',     java.version: '1.6.0_20'
Driver info: driver.version: RemoteWebDriver
Session ID: 95b80ea0-26ac-45e0-a407-79f5b687504a
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at  sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:188)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:498)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:244)
at org.openqa.selenium.remote.RemoteWebElement.findElements(RemoteWebElement.java:169)
at org.openqa.selenium.remote.RemoteWebElement.findElementsByTagName(RemoteWebElement.java:240)
at org.openqa.selenium.By$ByTagName.findElements(By.java:312)
at org.openqa.selenium.remote.RemoteWebElement.findElements(RemoteWebElement.java:151)
at Sorting.sorting_column(Sorting.java:68)
Run Code Online (Sandbox Code Playgroud)

以下是代码:

        //Fetching …
Run Code Online (Sandbox Code Playgroud)

selenium automation automated-tests

4
推荐指数
2
解决办法
3万
查看次数

如果不是SQLite中的EXISTS

如果devID已经存在,我如何检查devID是否已经存在然后插入以下查询:

INSERT  into profiles (devID,alert) VALUES ("ff",1) ;
Run Code Online (Sandbox Code Playgroud)

PS:我已经在SO中看到了这个解决方案,但不知道如何根据该解决方案修改我的查询.

任何帮助表示赞赏.

sql sqlite

1
推荐指数
1
解决办法
4949
查看次数

从ICS执行时弹出显示姜饼主题

从服务中,我试图展示吐司,而不管前景中有什么应用程序.为此,我使用主题为的活动Theme.Dialog

以下是我在清单中声明的​​方式:

    <activity android:process="@string/process" 
              android:name="com.android.blesettings.findmeserver.LaunchPopup" 
              android:configChanges="orientation|screenSize"
              android:theme="@android:style/Theme.Dialog" >
    </activity>
Run Code Online (Sandbox Code Playgroud)

除主题外,一切正常.弹出窗口的主题是Gingerbread(不确定为什么会发生!),虽然我在ICS中运行应用程序.我怎样才能解决这个问题,所以弹出的主题是ICS而不是Gingerbread

任何帮助表示赞赏

弹出显示姜饼主题

android

0
推荐指数
1
解决办法
879
查看次数