2016-04-14 11 views
0

私は通知プロジェクトに取り組んでいます。通知にURLリンクを渡す必要があります。ユーザーが通知をクリックするとアクティビティXに移動し、そのURLがアクティビティXにあるWebビューで開きます。通知のURLリンクを渡すにはどうすればいいのですか?それをクリックするとwebviewで開くはずですか?

これは私がやっているものです

...そのURLを開くのではなく、私のWebViewの中で、私が私のWebViewでそのリンクを開きたいphone..but中にブラウザの存在を選択するように求めているではない

Context context = this.getApplicationContext(); 
notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
// Intent mIntent = new Intent(this, MainActivity.class); 
Intent notificationIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")); 
Bundle bundle = new Bundle(); 
bundle.putString("test", "test"); 
notificationIntent.putExtras(bundle); 
pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

ただ!!!

ありがとうございます。

+0

サーバーには、サーバー側のリダイレクトを発行している。https://stackoverflow.com/questions/2893815/hello-webview-tutorial-opens-the-requested -add-in-android-browser-and-not/2893868?s = 1 | 0.7983#2893868 – CommonsWare

答えて

0

通知でURLを渡す必要はありません。それを通知の文字列として渡し、受信側でその文字列をURLに変換します。例えば

:receiverEndで

Bundle bundle = new Bundle(); 
bundle.putString("url", "www.google.com"); 
notificationIntent.putExtras(bundle); 

はこのようにそれを変換し、WebViewの中

String url = getArguments.getString("url"); 
Url myUrl = new Url(url); 

オープンmyUrl。

0

あなたはwebviewで新しいアクティビティを作成する必要があります。

使用あなたのWebViewの活動でこのコード

public class WebViewActivity extends Activity { 

    private WebView webView; 
Bundle extras; 
String loadurl; 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.webview); 
extras=getIntent().getExtras(); 
if(extras!=null){ 
loadurl=extras.getString("url","your default web page"); 
} 

     webView = (WebView) findViewById(R.id.webView1); 
     webView.getSettings().setJavaScriptEnabled(true); 
     webView.loadUrl(loadurl); 
    } 
} 
関連する問題