0
我想在android中創建一個應用程序,安裝後我需要在設備打開時設置爲默認應用程序。如何創建一個Android應用程序,該應用程序在打開設備時設置爲默認值
我曾嘗試以下
創建服務, 創建reciever到收到啓動完成事件
它不工作actually.If移除啓動了MainActivity的,它會顯示錯誤說
No Launcher activity found!
The launch will only sync the application package on the device!
我的清單文件
<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="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="sensorLandscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".MyService"
android:label="My Service" >
<intent-filter>
<action android:name="com.example.splash_test.MyService" />
</intent-filter>
</service>
<receiver
android:name=".receiver.MyReceiver"
android:label="MyReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity
android:name="com.example.splash_test.Screen1"
android:label="@string/app_name"
android:screenOrientation="sensorLandscape" >
</activity>
</application>
MyReceiver.java
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Intent serviceIntent = new Intent(context, MyService.class);
context.startService(serviceIntent);
}
}
}
MyService.java
public class MyService extends Service {
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Intent i = new Intent(this, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(i);
}
return null;
}
}
感謝Vishnu它的工作.. –
@Vishnu:請參閱編輯... –
@詹姆斯: - http://stackoverflow.com/questions/15085897/check-if-my-app-is-running -in-機器人 – Vishnu