2016-04-15 7 views
2

私はプログラムでアップデートをダウンロードしてインストールするルートアンドロイドデバイスを持っています。インストール中にユーザーのためのポップアップが表示されず、インストール中に発生した可能性のあるエラーをインストールまたは表示する権限が必要です。すべてがバックグラウンドで行われます。以下はインストールを実行する私のSoftwareInstallActivityです。キャッチインストール時にプログラムでエラーが発生する

public class SoftwareInstallActivity extends Activity{ 

private TextView titleView; 
private ImageView loadingView; 
private String fileName =null; 
private static Logger log=Logger.getRootLogger(); 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.alert_screen); 
    log.debug("Launching SoftwareInstall Activity"); 
    fileName=getIntent().getExtras().getString("FileName"); 
    if(fileName==null && fileName.length()==0){ 
     log.debug("filename is null or of zero length"); 
     return;   
    } 
    log.debug("Name of apk file"+fileName); 
    loadingView  = (ImageView)findViewById(R.id.loading);   
    titleView   = (TextView)findViewById(R.id.text1); 
    log.debug("Starting software Install"); 
    titleView.setText("Installing Software Update"); 
    try{ 
     Intent intent = new Intent(Intent.ACTION_VIEW); 
     intent.setDataAndType(Uri.fromFile(new File(fileName)), 
     "application/vnd.android.package-archive"); 
     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     startActivity(intent); 
    }catch(Exception e){ 
     e.printStackTrace(); 
    } 

} 
@Override 
public void onResume() { 
    super.onResume(); 
    log.debug("On Resume Software Install activity."); 
} 

@Override 
public void onPause(){ 
    super.onPause(); 
    log.debug("On Pause Software Install activity."); 
} 

} 

私が直面しています問題は、ソフトウェアでも任意の例外を与えることなく失敗してインストールし、私の試験のいくつかです。非常にまれなシナリオですが、私はまだそれを処理したいです。インストールが実際に成功したかどうかを確認する方法はありますか?以下の一連の行の成功または失敗をキャッチする方法はありますか?

Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(Uri.fromFile(new File(fileName)), 
     "application/vnd.android.package-archive"); 
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
startActivity(intent); 

助けてください。前もって感謝します!

答えて

0

startActivityForResultを使用すると、その方法で応答を確認できます。チェック: startActivityForResult

+0

startActivityForResultの問題は、常に0(失敗または成功)を返します。 [this](http://stackoverflow.com/questions/6157567/install-apk-programmatically-return-value)をチェックしてください。 – Exception

+0

startActivityForResult(intent、requestCode)を使用して、onActivityResultメソッドのrequestCodeとデータをチェックすることができます。 –

+0

私は失敗と成功の両方を試みましたが、requestCodeとresponseCodeは同じです。つまり、responseCodeは0、requestCodeは渡している整数です。 – Exception

関連する問題