私のアプリに呼び出されるURLを取得しようとしていますが、それが開いた後、それはちょうどいつもnull
です行う。ここでAndroidのURL体系:intent.getData()== null(PhoneGap)
は、私のマニフェストの関連する部分だ:
<activity android:name="myapp" android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="myapp" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
そして、ここでは私のJavaの:
@Override
public void onStart() {
super.onStart();
final Intent intent = getIntent();
Uri url = intent.getData();
Log.e("myLog", "Url = " + url);
}
ログは "意図= NULL" を出力している、と私はエラーを持っていません。
私はJava開発者ではありませんので、私は認識しない単純な問題があるかもしれません。私はsendJavascript
と私のPhoneGapアプリにこれを渡すつもりですが、PhoneGapアプリはこの問題には関係していないようです。
EDIT:
私はintent
をログインしたときにのみ、最初の<intent-filter>
を取得しているようです。ここでは、ログです:
03-13 12:36:18.593: E/MyAppLog(13793): Intent=Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.wd.myapp/.myapp (has extras) }
SOLUTION:
あなたのPhoneGapアプリを開くには、URLスキームを実装する方法についての記事の数十を通して注ぐと、それらのどれも非常に堅牢であることありませんか、全く働いた後、私は完全なソリューションを投稿し、誰かがそれが有用であることを願っています。
ステップ1:AndroidManifest.xml - これを<activity>
に追加し、 'urlScheme'を好きなものに変更します。この場合、urlScheme:///?key = valへのリンクをクリックするとアプリが開きます。
<intent-filter>
<data android:scheme="urlScheme" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
ステップ2:myApp.java - onCreate
の下に次の行を追加します。 singleTask
を使用している場合は、ロジックを関数に入れてください(onCreate
ではなく、トランペットされているため)。これにより、既に実行中であるかどうかにかかわらずアプリにリンクできます。
@Override
public void onStart() {
super.onStart();
final Intent intent = getIntent();
String url = intent.getDataString();
if(url != "" && url != null) {
super.sendJavascript("setTimeout(function() { handleOpenURL('" + url + "'); },1);");
}
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent); setIntent(intent);
}
オーバーライドonNewIntent
の説明についての受諾された回答を参照してください。
私は最終的な意図intent = getIntent()と思います。 Intent intent = intent.getIntent();最後にする必要があります。 –
どのように? 'インテント'はまだ存在しません。私はそれを試してみましょう。 – bearfriend
ええ、それは方法ではありません。私は「意図」をそのまま記録し、そこから何かを得たと信じています。データを取得するためにメソッドを呼び出すだけです。常にnullです。 – bearfriend