2016-07-20 14 views
0

私は、自分のアプリケーションがインボックスなどの別のアプリケーションを開くように通知する方法を試してきました。特定のアクティビティを開く方法しか見ていないし、アプリケーション全体を開くことができるかどうかわからない。Android:通知で別のアプリを開くにはどうすればよいですか?

+0

私はあなただけの適切意図を設定する必要があります...それが可能だと思う...しかし、私は試したことがありません..だから私は確認できません – W0rmH0le

+0

Androidには「アプリケーション全体」はありません。これは、Webページから「Webサイト全体」にリンクする方法を尋ねるのと同じです。 PackageManagerで使用するアプリケーションID( "パッケージ名")を知っている場合、アプリケーションのランチャーアクティビティを開始することができます。誰もがGoogle Inboxを使用しているわけではないので、どのアプリケーションを開くかをユーザーが決めることができるようにする必要があります。 – CommonsWare

答えて

1

はい。可能です。意図を適切に構成するだけで済みます。

注意

エンドユーザーが..あなたがしたいアプリをインストールしていないかもしれないので、あなたはそれを制御するためのメソッドを実装する必要が...

しかし、いずれにせよ、開くことができます独自の通知

異なるアプリは私がのWhatsAppのために、以下の例を作成しました。私は参考としてthis questionを使用しました。

Notification.Builder notiBuilder = new Notification.Builder(this); 
Intent intent = null; 

/* 
    START 
    Configure your intent here. 
    Example below opens the whatspp.. I got this example from https://stackoverflow.com/questions/15462874/sending-message-through-whatsapp/15931345#15931345 
    You must update it to open the app that you want. 

    If the app is not found, intent is null and then, click in notification won't do anything 
*/ 
PackageManager pm=getPackageManager(); 
try { 
    PackageInfo info = pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA); 
    intent = new Intent(Intent.ACTION_SEND); 
    intent.setPackage("com.whatsapp"); 
    intent.setType("text/plain"); 
} catch (PackageManager.NameNotFoundException e) { 
    // Package not found 
    intent = null; 
    e.printStackTrace(); 
} 
/* END */ 

if(intent != null) { 
    PendingIntent clickPendingIntent = PendingIntent.getActivity(
      this, 
      0, 
      intent, 
      PendingIntent.FLAG_UPDATE_CURRENT); 
    notiBuilder.setContentTitle("Title") 
      .setSmallIcon(R.drawable.common_google_signin_btn_icon_light) 
      .setContentText("Message") 
      .setContentIntent(clickPendingIntent) 
      .setLights(Color.BLUE, 3000, 3000); 
} else { 
    notiBuilder.setContentTitle("Title") 
      .setSmallIcon(R.drawable.common_google_signin_btn_icon_light) 
      .setContentText("Message") 
      .setLights(Color.BLUE, 3000, 3000); 
} 

Notification mNotificationBar = notiBuilder.build(); 
mNotificationBar.flags |= Notification.DEFAULT_SOUND; 
mNotificationBar.flags |= Notification.FLAG_SHOW_LIGHTS; 
mNotificationBar.flags |= Notification.FLAG_AUTO_CANCEL; 

NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Service.NOTIFICATION_SERVICE); 
mNotificationManager.notify(0, mNotificationBar); 

オープンダイヤラ

すぐ下のような意図を設定します。

intent = new Intent(Intent.ACTION_DIAL); 
intent.setData(Uri.parse("tel:")); 
+0

クール、これは多くの助けになりました! – TCTBO

関連する問題