此应用程序将在启动时运行并监视剪贴板以进行更改并执行某些操作;)
但它不会在启动时运行:(
我在整个网络上搜索解决方案,但我无法修复它。
这是AndroidManifest.xml内容:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.TB.Zedit"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light.NoTitleBar" >
<activity
android:name="com.TB.Zedit.ActMain"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" />
</intent-filter>
</activity>
<receiver android:name=".service_starter" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name=".clipboard_monitor"></service>
</application>
我希望我的应用程序在启动时运行并创建服务但不会发生任何事情
我的应用无法运行且没有错误;我真的很困惑
这是我的service_starter
代码
package com.TB.Zedit;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class service_starter extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED))
{
ComponentName clipboard_monitor_service=context.startService(new Intent("com.TB.Zedit.clipboard_monitor"));
if (clipboard_monitor_service==null)
{
Log.e("Zedit", "unable to start service");
}
else
{
Log.e("Zedit", "service STARTED");
}
}
}
}
目录下载
10-07 03:30:59.280: D/asset(1177): failed to open Zip archive '/data/app/com.TB.Zedit-2.apk'
10-07 03:30:59.280: W/PackageParser(1177): Unable to read AndroidManifest.xml of /data/app/com.TB.Zedit-2.apk
10-07 03:30:59.300: W/PackageSettings(1177): Skipping PackageSetting{b300fd20 com.TB.Zedit/10054} due to missing metadata
10-07 03:30:59.620: W/PackageSettings(1177): Skipping PackageSetting{b300fd20 com.TB.Zedit/10054} due to missing metadata
10-07 03:31:08.090: W/ActivityManager(1177): No content provider found for permission revoke: file:///data/local/tmp/Zedit.apk
10-07 03:31:08.090: W/ActivityManager(1177): No content provider found for permission revoke: file:///data/local/tmp/Zedit.apk
10-07 03:31:08.200: I/PackageManager(1177): Running dexopt on: com.TB.Zedit
10-07 03:31:08.200: I/PackageManager(1177): Package com.TB.Zedit codePath changed from /data/app/com.TB.Zedit-2.apk to /data/app/com.TB.Zedit-1.apk; Retaining data and using new
10-07 03:31:08.310: I/ActivityManager(1177): Force stopping com.TB.Zedit appid=10054 user=-1: update pkg
10-07 03:31:08.310: W/PackageManager(1177): Code path for pkg : com.TB.Zedit changing from /data/app/com.TB.Zedit-2.apk to /data/app/com.TB.Zedit-1.apk
10-07 03:31:08.310: W/PackageManager(1177): Resource path for pkg : com.TB.Zedit changing from /data/app/com.TB.Zedit-2.apk to /data/app/com.TB.Zedit-1.apk
10-07 03:31:08.470: D/BackupManagerService(1177): Received broadcast Intent { act=android.intent.action.PACKAGE_ADDED dat=package:com.TB.Zedit flg=0x4000010 (has extras) }
答案 0 :(得分:2)
我解决了这个问题
通过应用程序重新启动ON_BOOT_COMPLETED,应用程序必须具有2个功能:
1:应用必须至少有一项活动
2:app必须至少与用户一起运行
答案 1 :(得分:0)
添加此项以在活动代码之间启动所需的活动。假设,您希望在应用程序启动时启动此活动:
<activity
android:name="com.TB.Zedit.ActMain"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>``
</activity>
答案 2 :(得分:0)
首先,在你的清单中,
你用过这个:
<receiver android:name=".service_starter" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name=".service_starter"></service>
根据哪个是服务以及哪个是BroadcastReceiver来更改名称。
您需要一台广播接收器来启动您的应用程序。
示例:
<receiver android:name=".MyReceiver">
<intent-filter >
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
现在,在默认包中创建一个MyReceiver.java类,它将扩展BroadcastReceiver
,如下所示:
public class MyReciever extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Intent intent = new Intent(context, ActMain.class);
intent .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent );
}
}
您可以在此处阅读更多内容:Start activity or service on boot
希望这有帮助。