我有我的服务工作,但由于某种原因它不会开始我的活动。它也不会在 logcat 中显示错误。我希望我的服务开始另一个活动。那可能吗?我检查以确保我的 if 语句是正确的。它确实打印出你好。
服务代码如下:
package com.example.textsmslock;
import java.util.Iterator;
import java.util.List;
import android.app.ActivityManager;
import android.app.Service;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.IBinder;
import android.util.Log;
public class Logs extends Service
{
@Override
public IBinder onBind(Intent arg0){
// TODO Auto-generated method stub
return null;
}
@Override
public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
super.onStart(intent, startId);
System.out.println("LOGS STARTED");
ActivityManager am = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE);
List l = am.getRunningAppProcesses();
Iterator i = l.iterator();
PackageManager pm = this.getPackageManager();
while(i.hasNext())
{
ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo)(i.next());
try
{
CharSequence c = pm.getApplicationLabel(pm.getApplicationInfo(info.processName, PackageManager.GET_META_DATA));
Log.w("LABEL", c.toString());
//System.out.println("this is the charsequence: " + c);
//System.out.println("this is the log: " + Log.w("LABEL", c.toString()));
if(c.equals("Messaging"))
{
System.out.println("HELLO \n");
startActivity(new intent(("com.example.textsmslock.Enable"));
}
}
catch(Exception e)
{
//Name Not FOund Exception
}
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
System.out.println("LOGS STOPPED");
}
}
安卓清单
<activity
android:name=".Enable"
android:label="@string/title_activity_enable" >
<intent-filter>
<action android:name="com.example.textsmslock.Enable" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service android:name=".Logs" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</service>