我正在开发一款应用,当你向主屏幕按下按钮时,该应用就会打开。我做了其他所有事情,完成打开主页按钮部分的打开代码。我该怎么做呢? 任何帮助都会很棒。
如果需要,这是我的java代码:
package com.d4a.toolbelt;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
public class QuickLaunch extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quick_launch);
}
/** Called when the user clicks the music button */
public void music(View view) {
Intent intent = new Intent("android.intent.action.MUSIC_PLAYER");
startActivity(intent);
}
/** Called when the user clicks the play button */
public void play(View view) {
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.android.vending");
startActivity(launchIntent);
}
/** Called when the user clicks the web button */
public void web(View view) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.com/"));
startActivity(browserIntent);
}
/** Called when the user clicks the email button */
public void email(View view) {
Intent intent = getPackageManager().getLaunchIntentForPackage("com.android.email");
startActivity(intent);
}
/** Called when the user clicks the sms button */
public void chat(View view) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.d4a.sms","de.ub0r.android.smsdroid.ConversationListActivity"));
intent.putExtra("grace", "Hi");
startActivity(intent);
}
/** Called when the user clicks the settings button */
public void settings(View view) {
Intent intent = getPackageManager().getLaunchIntentForPackage("com.android.settings");
startActivity(intent);
}
/** Called when the user clicks the camara button */
public void cam(View view) {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, 0);
}
/** Called when the user clicks the video camara button */
public void video_cam(View view) {
Intent intent = new Intent("android.media.action.VIDEO_CAPTURE");
startActivityForResult(intent, 0);
}
}
先谢谢了一百万人!
答案 0 :(得分:1)
我发现你在清单中需要这行代码:
<intent-filter>
<action android:name="android.intent.action.ASSIST" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
由于家庭发射器是开源的,我得到了我的答案,我希望这可以帮助其他人在我的鞋子