2017-02-13 1 views
0

Je travaille sur une application (juste un petit projet amusant pour moi-même, je ne le mets pas sur le Play Store) qui va envoyer un toast. Mon but final est d'avoir une commande shell pour envoyer un toast. Je me fous de la façon dont j'obtiens ces résultats, je veux juste que ça marche.Personnalisation de mon application

Je pense que je vais avoir la commande shell qui envoie une intention à mon application. J'utilise une intention personnalisée:

<intent-filter> 
    <action android:name="com.tylerr147.toast" /> 
<category android:name="android.intent.category.DEFAULT" /> 
    <data android:mimeType="text/plain" /> 
</intent-filter> 

Lorsque j'utilise adb shell am start -a "com.tylerr147.toast" --es "android.intent.extra.TEXT" "toasty" -t "text/plain" pour commencer, mes application se bloque.

Voici mon AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.tylerr147.intenttoast" > 
<application android:allowBackup="true" 
android:icon="@drawable/ic_launcher" 
android:label="@string/app_name" 
android:theme="@style/AppTheme" > 
    <activity android:name=".handler" > 
     <intent-filter> 
     <action android:name="android.intent.action.SEND" /> 
<category android:name="android.intent.category.DEFAULT" /> 
    <data android:mimeType="text/plain" /> 
</intent-filter> 
<intent-filter> 
<action android:name="com.tylerr147.toast" /> 
    <category android:name="android.intent.category.DEFAULT"/> 
    <data android:mimeType="text/plain" /> 
</intent-filter> 
</activity> 
</application> 
</manifest> 

Et mon handler.java

package com.tylerr147.intenttoast; 
import android.app.*; 
import android.content.*; 
import android.net.*; 
import android.os.*; 
import android.widget.*; 
import java.util.*; 
import android.util.*; 

public class handler extends Activity 
{ 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     Intent intent = getIntent(); 
     String action = intent.getAction(); 
     String type = intent.getType(); 
     handleSendText(intent); 
    } 
    public void handleSendText(Intent intent) 
    { 
     try{ String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT); 
     if (sharedText != null) { 
      // Update UI to reflect text being shared 
      Toast.makeText(getApplicationContext(), sharedText, Toast.LENGTH_LONG).show(); 
     } 
     } catch(Exception e) { 
    Log.e("Boked", e.toString()); 
     } 
    } 
} 

Merci pour toute aide!

Répondre

0

Essayez cette

adb shell am broadcast -a "com.tylerr147.toast" --es "android.intent.extra.TEXT" "toasty" -t "text/plain" 

au lieu de

adb shell am start -a "com.tylerr147.toast" --es "android.intent.extra.TEXT" "toasty" -t "text/plain" 

remplacent commencer par diffusion.

espérons que cela fonctionne.

+0

Bien qu'il ne se soit pas crashé cette fois-ci, il n'a pas non plus fait le toast. –